package com.wskj.common.utils.common;

import com.wskj.common.exception.CustomException;
import jodd.util.StringUtil;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;

import java.util.Collection;

/**
* Filename: AssertUtils.java
* Description: 断言工具类
* Copyright: Copyright (c) 2016-2019 All Rights Reserved. 
* Company: wsdz.com Inc. 
*
* @author: gunk
* @version: 1.0 
* Create at: 2022/8/17 9:34 
*
* Modification History: 
* Date Author Version Description 
* ------------------------------------------------------------------ 
* 2022/8/17 guqk 1.0 1.0 Version 
*/
public class AssertUtils {

    private AssertUtils() {
    }

    public static void isNull(Object obj, String message) {
        if (obj != null) {
            throw new CustomException(message);
        }
    }

    public static void notNull(Object obj, String message) {
        if (obj == null) {
            throw new CustomException(message);
        }
    }

    public static void isNull(@Nullable Collection<?> collection, String message) {
        if (!CollectionUtils.isEmpty(collection)) {
            throw new CustomException(message);
        }
    }

    public static void notNull(@Nullable Collection<?> collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new CustomException(message);
        }
    }

    public static void isTrue(boolean value, String message) {
        if (!value) {
            throw new CustomException(message);
        }
    }

    public static void isFalse(boolean value, String message) {
        if (value) {
            throw new CustomException(message);
        }
    }

    public static void isEmpty(String value, String message) {
        if (StringUtil.isNotEmpty(value)) {
            throw new CustomException(message);
        }
    }

    public static void notEmpty(String value, String message) {
        if (StringUtil.isEmpty(value)) {
            throw new CustomException(message);
        }
    }

    public static void isBlank(String value, String message) {
        if (StringUtil.isNotBlank(value)) {
            throw new CustomException(message);
        }
    }

    public static void notBlank(String value, String message) {
        if (StringUtil.isBlank(value)) {
            throw new CustomException(message);
        }
    }
}
